package com.joven.infra.common.util;

import com.joven.infra.common.exception.ApiException;
import lombok.experimental.UtilityClass;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.Objects;


/**
 * 数据校验工具
 */
@UtilityClass
public class CheckUtils {
    public void assertFalse(boolean condition, ApiException exception) {
        if (condition) {
            throw exception;
        }
    }

    public void assertTrue(boolean condition, ApiException exception) {
        if (!condition) {
            throw exception;
        }
    }

    public void notBlank(String obj, ApiException exception) {
        if (StringUtils.isBlank(obj)) {
            throw exception;
        }
    }

    public void notNull(Object o, ApiException exception) {
        if (Objects.isNull(o)) {
            throw exception;
        }
    }

    public void notEmpty(Collection<?> coll, ApiException exception) {
        if (CollectionUtils.isEmpty(coll)) {
            throw exception;
        }
    }
}
